package com.zzu.view.activity;

import android.app.Activity;
import android.content.Intent;
import android.media.Image;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageButton;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.widget.ViewPager2;

import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;
import com.zzu.R;
import com.zzu.adapter.ViewpagerStateAdapter;
import com.zzu.view.fragment.ExpressInfoFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @description:
 * @author: bytedance
 * @date: 2021-05-21 22:44
 */
public class ExpressInfoAndMapActivity extends FragmentActivity implements View.OnClickListener {

    private static final String TAG = ExpressInfoAndMapActivity.class.getName();
    //用于后退的按钮
    @BindView(R.id.ib_good_info_back)
    ImageButton ibGoodInfoBack;
    @BindView(R.id.ib_refresh)
    ImageButton ibRefresh;
    @BindView(R.id.tab_layout)
    TabLayout tabLayout;
    @BindView(R.id.viewpager2)
    ViewPager2 viewPager2;
    String packageId = null;
    String nowAddress = null;
    List<String> strs = new ArrayList<>();
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_expressinfo_map);
        //进行组件的绑定
        ButterKnife.bind(this);

        Intent intent = getIntent();
        packageId = intent.getStringExtra(ExpressInfoFragment.PACKAGE_ID);
        nowAddress = intent.getStringExtra(ExpressInfoFragment.NOW_ADDRESS);

        //初始化监听
        initActions();

        Log.i(TAG,"获取到的包裹信息"+packageId+","+nowAddress);

        strs.add("基本信息");
        strs.add("物流信息");

        ViewpagerStateAdapter adapter = new ViewpagerStateAdapter(getSupportFragmentManager(),getLifecycle(),packageId,nowAddress);
        viewPager2.setAdapter(adapter);

        //用TabLayoutMediator将TabLayout和ViewPager2结合
        new TabLayoutMediator(tabLayout, viewPager2, (tab, position) -> tab.setText(strs.get(position))).attach();


    }

    private void initActions() {
        //后退按钮监听
        ibGoodInfoBack.setOnClickListener(this);
        ibRefresh.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.ib_good_info_back:
                //回退按钮
                finish();
                break;
            case R.id.ib_refresh:
                //刷新地图界面

                break;
            default:
                break;
        }
    }
}
